package cn.dengta.webapp.trade.vo;

import java.util.Date;
import java.util.Map;

import cn.dengta.common.model.Status;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.trade.entity.CashAccount;
import cn.dengta.webapp.trade.entity.CashAccount.CashAccountStatus;
import cn.dengta.webapp.trade.model.PaymentMethod;
import cn.dengta.webapp.trade.form.PayerMaxReqForm;
import cn.dengta.webapp.trade.model.Currency;
import cn.dengta.webapp.trade.model.PayPlatform;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.X;

@Getter
@Setter
public class CashAccountVO extends AbstractVO<CashAccount> {

	private Map<String, Object> user;
	private Map<String, Object> verifyUser;
	/**
	 * 支付平台
	 *
	 * @see cn.dengta.webapp.trade.model.PayPlatform
	 */
	private transient Integer platform;
	/** 手机号 */
	private String phone;
	/** 真实姓名 */
	private String realName;
	/** 提现账号 */
	private String account;
	/** 提现币种 */
	private transient String currency;
	/** 业务状态：-1=无效（应账户不对导致提现失败）；0=初始化；1=有效（已经提现成功过） */
	private Integer status;
	/** 是否可解绑 */
	private Boolean canUnbind;

	/** 国家 */
	private String country;
	/**
	 * 1=银行卡；2=钱包；3支付宝
	 *
	 * @see PaymentMethod
	 */
	private Integer type;
	/** 银行卡Code */
	private String bankCode;
	/** 第一个名称 */
	private transient String firstName;
	/** 最后一个名称 */
	private transient String lastName;
	/** 中间名 */
	private transient String middleName;

	public static String[] frontList = { "type", "bankCode" };

	public static CashAccountVO fromFront(CashAccount source) {
		CashAccountVO copy = copy(source, CashAccountVO::new, frontList);
		replaceVO(source, copy);
		return copy;
	}

	public static CashAccountVO from(CashAccount source) {
		CashAccountVO vo = copy(source, CashAccountVO::new);
		replaceVO(source, vo);
		return vo;
	}

	private static void replaceVO(CashAccount source, CashAccountVO vo) {
		if (source != null && vo != null) {
			PayPlatform platform = PayPlatform.of(source.getPlatform());
			if (platform.liveCash) {
				vo.setRealName(PaymentMethod.ALIPAY.getLabel().equals(source.getType()) ? source.getRealName() : PayerMaxReqForm.buildFullName(source.getCountry(), source.getFirstName(), source.getMiddleName(), source.getLastName()));
			}
		}
	}

	public String getPlatform_() {
		return X.map(PayPlatform.of(platform), PayPlatform::name);
	}

	public String getStatus_() {
		if (Status.NO.eq(status)) {
			status = 1;
		}
		return X.map(CashAccountStatus.of(status), CashAccountStatus::getLabel);
	}

	public String getCurrency_() {
		return X.map(Currency.of(currency), Currency::getLabel);
	}

	public Date getAddTime() {
		return super.getAddTime();
	}

	public String getType_() {
		return X.map(PaymentMethod.of(type), PaymentMethod::getInfo);
	}

}
